//
//  SSIMMessageErrorManager.m
//  QBNIMClient
//
//  Created by 秦雨 on 17/6/7.
//  Copyright © 2017年 秦雨. All rights reserved.
//

#import "SSIMMessageErrorManager.h"

@implementation SSIMMessageErrorManager

SingletonImplementation(SSIMMessageErrorManager)

-(SDK_MESSAGE_RESULT)getMessageStatus:(SSIMMessage *)message
{
    if (message==nil ||
        message.userid<=0 ||
        message.toid<=0 ||
        !message.msgContent ||
        IsStrEmpty(message.sendUserName)) {
        return SDK_MESSAGE_LOSE;
    }else{
        
        NSPredicate *friendPre = [NSPredicate predicateWithFormat:@"fdOwnId = %lld AND fdPeerId = %lld",OWNERID,message.toid];
        FDListEntity *friend = [FDListEntity NIM_findFirstWithPredicate:friendPre];
        if (!friend) {
            return SDK_MESSAGE_USER_NOTFOUND;
        }
        
        GroupList *group = [GroupList instancetypeFindGroupId:message.toid];
        if (!group) {
            return SDK_MESSAGE_GROUP_NOTFOUND;
        }
        
        switch (message.chatType) {
            case GROUP:
            case PUBLIC:
            case PRIVATE:
                
                break;
                
            default:
                return SDK_MESSAGE_CT_NOTFOUND;
                break;
        }
        
        switch (message.mtype) {
            case TEXT:
            case ITEM:
            case IMAGE:
            case VOICE:
            case SMILEY:
            case JSON:
            case MAP:
                
                break;
            default:
                return SDK_MESSAGE_MT_NOTFOUND;
                break;
        }
        
        switch (message.stype) {
            case CHAT:
            case RED_PACKET:
            case ORDER:
            case VCARD:
            case TIP:
                
                break;
            default:
                return SDK_MESSAGE_ST_NOTFOUND;
                break;
        }
        
        
    }
    
    return SDK_MESSAGE_OK;
}


-(SSIMMessage *)transChatEntity:(ChatEntity *)chatEntity
{
    if (!chatEntity) {
        return nil;
    }
    SSIMMessage *message = [[SSIMMessage alloc] init];
    message.userid = chatEntity.userId;
    message.toid = chatEntity.opUserId;
    message.chatType = chatEntity.chatType;
    message.mtype = chatEntity.mtype;
    message.stype = chatEntity.stype;
    message.etype = chatEntity.ext;
    message.msgContent = chatEntity.msgContent;
    message.bid = chatEntity.bId;
    message.wid = chatEntity.wId;
    message.cid = chatEntity.cId;
    [message setValue:@(chatEntity.messageId) forKey:NSStringFromSelector(@selector(messageId))];
    return message;
}

@end
